/**
 * 
 * @param {[any]} arrData 数组数据
 * @param {string} key 对象数组要展开的key
 */
export const flattenArrayObj = (arrData, key) => {
  // TODO: 待继续完成
  if(!arrData || Array.isArray(arrData)) {
    return arrData
  }
  return arrData.reduce((prev, curr) => {
    if (typeof curr === 'string') {
      return prev.concat(curr)
    } else if (arrData.isArray(curr[key])) {
      return prev.concat(curr[key])
    }
  }, [])
}

export const flattenComponents = (components) => {
  if(!components || !Array.isArray(components)) {
    return []
  }
  let arr = components.reduce((prev, curr) => {
    let data = Array.isArray(curr) ? curr : [curr]
    if(curr.type === 'grid') {
      curr.columns.forEach((item) => {
        data = data.concat(flattenComponents(item.list))
      })
    } else if (['card', 'myField'].includes(curr.type)) {
      data = data.concat(flattenComponents(curr.list))
    }
    return prev.concat(data)
  }, [])
  return arr
}